﻿using System.Configuration;
using PlanningGIS.Util.IO;
using PlanningGIS.Framework.Config;
using System.IO;

namespace PlanningGIS.Framework
{
    /// <summary>
    /// 系统配置参数信息
    /// </summary>
    public class AppConfig
    {
        /// <summary>
        /// 系统启动路径
        /// </summary>
        private static string _StartupPath = "";
        /// <summary>
        /// 获取当前系统的启动路径
        /// </summary>
        public static string StartupPath
        {
            get
            {
                if (string.IsNullOrEmpty(_StartupPath))
                    _StartupPath = PathHelper.GetAppPath();
                return _StartupPath;
            }
        }

        /// <summary>
        /// 获取系统图片路径
        /// </summary>
        public static string ImagePath
        {
            get { return StartupPath + "\\Images"; }
        }

        /// <summary>
        /// 获取系统配置所在的文件夹名称
        /// </summary>
        public static string FolderValue
        {
            get
            {
                return ConfigurationManager.AppSettings.Get("Folder");
            }
        }

        /// <summary>
        /// 系统配置所在的根目录
        /// </summary>
        private static string _SysFolder = "";
        /// <summary>
        /// 获取系统配置所在的根目录
        /// </summary>
        public static string SysFolder
        {
            get
            {
                if (string.IsNullOrEmpty(_SysFolder))
                {
                    _SysFolder = PathHelper.GetAppSettingPath("Folder");
                }
                return _SysFolder;
            }
        }

        /// <summary>
        /// 获取系统配置文件目录
        /// </summary>
        public static string ConfigPath
        {
            get
            {
                return SysFolder + "\\Config";
            }
        }

        /// <summary>
        /// 获取Server文件目录
        /// </summary>
        public static string ServerDirectory
        {
            get { return SysFolder + "\\Server"; }
        }

        /// <summary>
        /// 获取Ags文件目录
        /// </summary>
        public static string AgsFileDirectory
        {
            get { return ServerDirectory + "\\AgsFiles"; }
        }

        /// <summary>
        /// 服务输出文件目录
        /// </summary>
        public static string OutputsDirectory
        {
            get { return ServerDirectory + "\\Outputs"; }
        }

        /// <summary>
        /// python脚本文件目录
        /// </summary>
        public static string ScriptsDirectory
        {
            get { return _StartupPath + "\\Scripts"; }
        }

        /// <summary>
        /// 获取坐标系文件路径
        /// </summary>
        public static string CoordinatePath
        {
            get { return SysFolder + "\\Coordinate Systems"; }
        }

        /// <summary>
        /// 获取数据文件目录
        /// </summary>
        public static string DataPath
        {
            get { return SysFolder + "\\Data"; }
        }

        /// <summary>
        /// 获取报表文件目录
        /// </summary>
        public static string ReportPath
        {
            get { return SysFolder + "\\Report"; }
        }


        /// <summary>
        /// 系统数据文件全路径
        /// </summary>
        public static string DataFullName { get { return SysFolder + "\\Data\\SysData.gdb"; } }

        /// <summary>
        /// 获取Style目录
        /// </summary>
        public static string StylePath
        {
            get { return SysFolder + "\\Style"; }
        }

        /// <summary>
        /// 获取parameter目录
        /// </summary>
        public static string ParameterPath
        {
            get { return SysFolder + "\\parameter"; }
        }

        /// <summary>
        /// 获取Temp路径
        /// </summary>
        public static string TempPath
        {
            get
            {
                string path = SysFolder + "\\Temp";
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
                return path;
            }
        }

        /// <summary>
        /// 是否单机运行
        /// </summary>
        public static bool IsRunLocal { get; set; }

        /// <summary>
        /// 系统配置信息
        /// </summary>
        private static SystemConfig _SystemConfig = null;

        /// <summary>
        /// 获取系统配置信息实例
        /// </summary>
        public static SystemConfig SystemConfig
        {
            get
            {
                if (_SystemConfig == null)
                {
                    _SystemConfig = ConfigHelper.GetObject<SystemConfig>();
                }
                return _SystemConfig;
            }
        }
    }
}
